package com.bravo.mvpkotlin.base

import android.app.ProgressDialog
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import org.jetbrains.anko.indeterminateProgressDialog

/**
 * Created by Administrator on 2017/6/21 0021.
 */
abstract class BaseActivity : AppCompatActivity() {

    var progressDialog:ProgressDialog? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(attachLayoutId())
        setUpComponent(BaseApp.getApplication().getAppComponent())
        initViews()
    }

    /**
     * 布局id
     */
    abstract fun attachLayoutId():Int

    /**
     * 加载V
     */
    abstract fun initViews()

    abstract fun setUpComponent(appComponent: AppComponent)

    open fun startLoading() {
        if (null === progressDialog){
            progressDialog = indeterminateProgressDialog("正在加载...")
        }else{
            progressDialog?.show()
        }
    }

    open fun stopLoading() {
        progressDialog?.dismiss()
    }

    override fun onDestroy() {
        super.onDestroy()
        progressDialog?.dismiss()
    }
}